package com.sptpc.springbootmybatis.service;

import com.sptpc.springbootmybatis.dao.FicationMapper;
import com.sptpc.springbootmybatis.model.Fication;
import com.sptpc.springbootmybatis.vo.FicationVo;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class FicationService {
    @Autowired
    private FicationMapper ficationMapper;


    public Fication saveFication(FicationVo ficationVo) {
        Fication fication = new Fication();
        fication.setName(ficationVo.getName());
        fication.setCreateTime(new Date());
        fication.setUpdateTime(new Date());
        if(ficationMapper.insertSelective(fication)!=0){
            return findOne(ficationVo.getName());
        }
        return null;
    }


    public Fication update(FicationVo ficationVo) {
        Fication fication = new Fication();
        fication.setId(ficationVo.getId());
        fication.setName(ficationVo.getName());
        fication.setUpdateTime(new Date());
        if(ficationMapper.updateByPrimaryKeySelective(fication)!=0) {
            return ficationMapper.selectByPrimaryKey(fication.getId());
        }
        return null;
    }

}
